#ifndef PLAYLISTMODEL_H
#define PLAYLISTMODEL_H

#include <QAbstractListModel>
#include <QVariant>
#include <QMap>
#include <QMediaPlaylist>
#include <QNetworkAccessManager>
#include <QNetworkReply>

class PlayListModel : public QAbstractListModel
{
    Q_OBJECT
    Q_ENUMS(InfoRoles)
public:
    enum InfoRoles {
        TitleRole = 0,
        ArtistRole,
        AlbumRole
    };

    explicit PlayListModel(QObject *parent=0);
    virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QModelIndex index(int row, int column, const QModelIndex &parent) const;
    virtual int rowCount(const QModelIndex &parent) const;
    virtual QVariant data(const QModelIndex &index, int role) const;
    void setPlayList(QMediaPlaylist *playlist);
    void addToPlaylist(const QList<QUrl> urls);
    QModelIndex getIndex(int row);
    Q_INVOKABLE int getCurrentIndex();
    Q_INVOKABLE QVariant get(int row,InfoRoles role);
    Q_INVOKABLE void setPlayListFromHttp(QString url);
signals:
    void playListChanged(int row);
public slots:
    void jump(int row);
    void previous();
    void next();
    void onEror(QNetworkReply::NetworkError code);
    void onFinished();
protected:
    QHash<int, QByteArray> roleNames() const;
private:
    QMediaPlaylist *m_playList;
    QNetworkAccessManager m_nam;
    QNetworkReply *m_reply;
    QMap<int,QVariantMap> m_data;
};

#endif // PLAYLISTMODEL_H
